home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / TCL1 / CDICTION / CDICTION.H < prev    next >
Text File  |  1990-01-12  |  2KB  |  80 lines

  1. /********************************************************************
  2. CDictionary.h
  3.  
  4.     Subclass of CCollection that implements a dictionary. See
  5.     CDictionary.doc for more info
  6.     
  7. SUPERCLASS = CCollection
  8. ********************************************************************/
  9.  
  10.  
  11. #define _H_CDictionary
  12.  
  13. #include "CCollection.h"
  14. #include "defs.h"
  15.  
  16. typedef uInt32    (*MapProc)( void *key);
  17. typedef Boolean    (*CompareProc)( void *key1, void *key2);
  18.  
  19. typedef struct tAssociation
  20. {
  21.     CObject    *value;
  22.     char    key[];
  23.     
  24. } tAssociation, *tAssociationPtr;
  25.  
  26. /*    Iterator function types for dictionary. DictIterators
  27.     are passed to DoForEach. Do For each calls a DictIterator
  28.     with a pointer to an association. DictIterator1 should be
  29.     passed to DoForEach1. It is presented with a pointer to
  30.     an association and a longword parameter */
  31.     
  32. typedef void (*DictIterator)( tAssociationPtr);
  33. typedef void (*DictIterator1)( tAssociationPtr, Int32);
  34.  
  35.  
  36. struct CDictionary : CCollection
  37. {
  38.     /* instance variables */
  39.     
  40.     Int16        keySize;    /* size of keys */
  41.     Int16        slotSize;    /* size of each slot (bucket) = keySize + sizeof(ptr to object) */
  42.     Int32        tableSize;    /* current size of table */
  43.     Int32        slotsLeft;    /* number of empty slots in table */
  44.     Handle        table;        /* hash table */
  45.     
  46.     MapProc        map;        /* the mapping function */
  47.     CompareProc    compare;    /* the comparison function */
  48.     
  49.     struct CDataFile *itsFile;    /* not-nil while reading or writing a file */
  50.     
  51.     /* public methods */
  52.     
  53.     virtual Boolean IDictionary( Int16 keySize, MapProc map, CompareProc compare,
  54.                     Int32 initialSize);    
  55.                     
  56.     virtual void Dispose( void);
  57.     virtual void DisposeAll( void);
  58.     virtual void DisposeItems( void);
  59.     
  60.     virtual void Add( void *key, CObject *value);
  61.     virtual void AddAll( CDictionary *aDictionary);
  62.     virtual void Remove( void *key);
  63.     
  64.     virtual CObject *Lookup( void *key);
  65.     
  66.     virtual Boolean IncludesKey( void *key);
  67.     virtual Boolean IncludesValue( CObject *anObject);
  68.     
  69.     virtual void DoForEach( DictIterator actionProc);
  70.     virtual void DoForEach1( DictIterator1 actionProc, Int32 aParam);
  71.     
  72.     virtual CObject *Copy( void);
  73.         
  74.     /* private methods */
  75.     
  76.     virtual void MoreSlots( void);
  77.     virtual Int32 _lookup( void *key);
  78.     
  79. };
  80.